import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login.vue'
import home from '@/views/Home.vue'
import { userStore } from '@/store'
const Router = createRouter({
	history: createWebHistory(),
	routes: [{
		path: '/login',
		name: 'login',
		meta: { title: '登录' },
		component: Login
	}, {
		path: '/',
		name: 'home',
		meta: { title: '首页' },
		redirect: 'dashboard',
		children: [{
			path: 'dashboard',
			name: 'dashboard',
			meta: { title: '仪表盘' },
			component: () => import('../views/home/dashboard.vue')
		}, {
			path: 'banner',
			name: 'banner',
			meta: { title: '焦点图管理' },
			component: () => import('../views/home/banner.vue')
		}, {
			path: 'about',
			name: 'company',
			meta: { title: '企业特色管理' },
			component: () => import('../views/home/company.vue')
		}, {
			path: 'edit/:id',
			name: 'edit',
			meta: { title: '修改焦点图' },
			component: () => import('../views/home/banner/edit.vue')
		}, {
			path: 'create',
			name: 'create',
			meta: { title: '添加焦点图' },
			component: () => import('../views/home/banner/edit.vue')
		}, {
			path: 'aboutedit/:id',
			name: 'aboutedit',
			meta: { title: '更新首页公司简介' },
			component: () => import('../views/home/banner/aboutEdit.vue')
		}, {
			path: 'aboutcreate',
			name: 'aboutcreate',
			meta: { title: '添加首页公司简介' },
			component: () => import('../views/home/banner/aboutEdit.vue')
		}, {
			path: 'aboutUs',
			name: 'aboutUs',
			meta: { title: '关于我们' },
			component: () => import('../views/home/aboutUs.vue')
		}, {
			path: 'aboutUsedit/:id',
			name: 'aboutUsedit',
			meta: { title: '更新' },
			component: () => import('../views/home/banner/aboutUsEdite.vue')
		}, {
			path: 'aboutUscreate',
			name: 'aboutUscreate',
			meta: { title: '添加' },
			component: () => import('../views/home/banner/aboutUsEdite.vue')
		}, {
			path: 'products',
			name: 'products',
			meta: { title: '产品管理' },
			component: () => import('../views/home/products.vue')
		}, {
			path: 'productsEdit/:id',
			name: 'productsEdit',
			meta: { title: '产品更新' },
			component: () => import('../views/home/banner/productsEdit.vue')
		}, {
			path: 'productsCreate',
			name: 'productsCreate',
			meta: { title: '产品添加' },
			component: () => import('../views/home/banner/productsEdit.vue')
		}, {
			path: 'categories',
			name: 'categories',
			meta: { title: '分类管理' },
			component: () => import('../views/home/categories.vue')
		}, {
			path: 'categoryEdite/:id',
			name: 'categoryEdite',
			meta: { title: '更新分类' },
			component: () => import('../views/home/banner/categoryEdite.vue')
		}, {
			path: 'categoryCreate',
			name: 'categoryCreate',
			meta: { title: '添加分类' },
			component: () => import('../views/home/banner/categoryEdite.vue')
		}, {
			path: 'user',
			name: 'user',
			meta: { title: '用户管理' },
			component: () => import('../views/home/user.vue')
		}, {
			path: 'userEdit/:id',
			name: 'userEdit',
			meta: { title: '修改用户' },
			component: () => import('../views/home/banner/userbianji.vue')
		}, {
			path: 'userCreate',
			name: 'userCreate',
			meta: { title: '添加用户' },
			component: () => import('../views/home/banner/userEdit.vue')
		}, {
			path: 'change/:id',
			name: 'change',
			meta: { title: '添加用户' },
			component: () => import('../views/home/banner/changepas.vue')
		}],
		component: home
	}]
})
Router.beforeEach((to, from, next) => {
	const store = userStore()
	let token = store.token
	if (to.path == '/login' && token) {
		next(false)
	} else if (to.path != '/login' && !token) {
		next('/login')
	} else {
		next()
	}
})
export default Router
